
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Django 3.1 版本发行说明 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Django 3.0.14 版本发行说明" href="3.0.14.html" />
    <link rel="prev" title="Django 3.1.1 版本发行说明" href="3.1.1.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="3.1.1.html" title="Django 3.1.1 版本发行说明">previous</a>
     |
    <a href="index.html" title="发行说明" accesskey="U">up</a>
   |
    <a href="3.0.14.html" title="Django 3.0.14 版本发行说明">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="releases-3.1">
            
  <div class="section" id="s-django-3-1-release-notes">
<span id="django-3-1-release-notes"></span><h1>Django 3.1 版本发行说明<a class="headerlink" href="#django-3-1-release-notes" title="永久链接至标题">¶</a></h1>
<p><em>2020 年 8 月 4 日</em></p>
<p>欢迎来到 Django 3.1 版本！</p>
<p>此版本说明涵盖了一些 <a class="reference internal" href="#whats-new-3-1"><span class="std std-ref">新特性</span></a> ，以及从 Django 3.0 或更早版本升级时需要注意的 <a class="reference internal" href="#backwards-incompatible-3-1"><span class="std std-ref">向后不兼容</span></a> 的地方。我们已经 <a class="reference internal" href="#removed-features-3-1"><span class="std std-ref">删除了一些过期的功能</span></a> ，并且已经开始 <a class="reference internal" href="#deprecated-features-3-1"><span class="std std-ref">淘汰一些特性</span></a> 。</p>
<p>如果你要更新现有的项目，请看 <a class="reference internal" href="../howto/upgrade-version.html"><span class="doc">升级 Django 到最新的版本</span></a> 指南。</p>
<div class="section" id="s-python-compatibility">
<span id="python-compatibility"></span><h2>Python 兼容性<a class="headerlink" href="#python-compatibility" title="永久链接至标题">¶</a></h2>
<p>Django 3.1 支持 Python 3.6、3.7、3.8 和 3.9（从 3.1.3 开始）。我们 <strong>强烈推荐</strong> 且官方只支持每个系列的最新版本。</p>
</div>
<div class="section" id="s-what-s-new-in-django-3-1">
<span id="s-whats-new-3-1"></span><span id="what-s-new-in-django-3-1"></span><span id="whats-new-3-1"></span><h2>Django 3.1 新特性<a class="headerlink" href="#what-s-new-in-django-3-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-asynchronous-views-and-middleware-support">
<span id="asynchronous-views-and-middleware-support"></span><h3>异步视图和中间件支持<a class="headerlink" href="#asynchronous-views-and-middleware-support" title="永久链接至标题">¶</a></h3>
<p>Django 现在支持完全异步的请求路径，包括：</p>
<ul class="simple">
<li><a class="reference internal" href="../topics/http/views.html#async-views"><span class="std std-ref">异步视图</span></a></li>
<li><a class="reference internal" href="../topics/http/middleware.html#async-middleware"><span class="std std-ref">异步中间件</span></a></li>
<li><a class="reference internal" href="../topics/testing/tools.html#async-tests"><span class="std std-ref">异步测试和测试客户端</span></a></li>
</ul>
<p>要开始使用异步视图，你需要使用 <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code> 来声明一个视图：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">async</span> <span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s1">&#39;Hello, async world!&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>无论你是在 WSGI 或 ASGI 模式下运行，都支持所有的异步功能。但是，在 WSGI 模式下使用 async 代码会有性能上的惩罚。你可以在 <a class="reference internal" href="../topics/async.html"><span class="doc">异步支持</span></a> 文档中阅读更多的具体内容。</p>
<p>你可以自由地混合异步和同步视图、中间件和测试，只要你愿意。Django 会确保你最终使用正确的执行上下文。我们希望大多数项目会保持大部分视图的同步，只有少数视图在异步模式下运行，但这完全是你的选择。</p>
<p>Django 的 ORM、缓存层和其他做长期网络调用的代码还不支持异步访问。我们希望在即将发布的版本中增加对它们的支持。但是，异步视图是很理想的，如果你在视图里面做了大量的 API 或 HTTP 调用，你现在可以原生地将所有这些 HTTP 调用并行进行，以大大加快你的视图的执行速度。</p>
<p>异步支持应该是完全向后兼容的，我们已经尝试确保它不会对你现有的同步代码造成速度上的倒退。它应该不会对任何现有的 Django 项目产生明显的影响。</p>
</div>
<div class="section" id="s-jsonfield-for-all-supported-database-backends">
<span id="jsonfield-for-all-supported-database-backends"></span><h3>JSONField 适用于所有支持的数据库后端。<a class="headerlink" href="#jsonfield-for-all-supported-database-backends" title="永久链接至标题">¶</a></h3>
<p>Django 现在包含 <a class="reference internal" href="../ref/models/fields.html#django.db.models.JSONField" title="django.db.models.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">models.JSONField</span></code></a> 和 <a class="reference internal" href="../ref/forms/fields.html#django.forms.JSONField" title="django.forms.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">forms.JSONField</span></code></a>，可以在所有支持的数据库后端使用。这两个字段都支持使用自定义 JSON 编码器和解码器。模型字段支持自省、<a class="reference internal" href="../topics/db/queries.html#querying-jsonfield"><span class="std std-ref">查找和变换</span></a>，这些功能以前只有 PostgreSQL 才有：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">ContactInfo</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">JSONField</span><span class="p">()</span>

<span class="n">ContactInfo</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span>
    <span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;John&#39;</span><span class="p">,</span>
    <span class="s1">&#39;cities&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;London&#39;</span><span class="p">,</span> <span class="s1">&#39;Cambridge&#39;</span><span class="p">],</span>
    <span class="s1">&#39;pets&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;dogs&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;Rufus&#39;</span><span class="p">,</span> <span class="s1">&#39;Meg&#39;</span><span class="p">]},</span>
<span class="p">})</span>
<span class="n">ContactInfo</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
    <span class="n">data__name</span><span class="o">=</span><span class="s1">&#39;John&#39;</span><span class="p">,</span>
    <span class="n">data__pets__has_key</span><span class="o">=</span><span class="s1">&#39;dogs&#39;</span><span class="p">,</span>
    <span class="n">data__cities__contains</span><span class="o">=</span><span class="s1">&#39;London&#39;</span><span class="p">,</span>
<span class="p">)</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
</pre></div>
</div>
<p>如果你的项目使用了 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.JSONField</span></code>，加上相关的表单字段和变换，你应该调整使用新的字段，并生成和应用数据库迁移。目前，旧的字段和变换体作为新字段的引用留存下来，并且 <a class="reference internal" href="#deprecated-jsonfield"><span class="std std-ref">从这个版本开始取消</span></a>。</p>
</div>
<div class="section" id="s-default-hashing-algorithm-settings">
<span id="s-default-hashing-algorithm-usage"></span><span id="default-hashing-algorithm-settings"></span><span id="default-hashing-algorithm-usage"></span><h3><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code> 配置<a class="headerlink" href="#default-hashing-algorithm-settings" title="永久链接至标题">¶</a></h3>
<p>新的 <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_HASHING_ALGORITHM"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code></a> 过渡性配置允许指定默认的哈希算法，用于对 cookie、管理员站点中的密码重置令牌、用户会话以及 <a class="reference internal" href="../topics/signing.html#django.core.signing.Signer" title="django.core.signing.Signer"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.core.signing.Signer</span></code></a> 和 <a class="reference internal" href="../topics/signing.html#django.core.signing.dumps" title="django.core.signing.dumps"><code class="xref py py-meth docutils literal notranslate"><span class="pre">django.core.signing.dumps()</span></code></a> 创建的签名进行编码。</p>
<p>Django 3.1 中增加了对 SHA-256 的支持。如果你要将同一个项目的多个实例升级到 Django 3.1，你应该在过渡期间将 <a href="#id1"><span class="problematic" id="id2">:set:`DEFAULT_HASHING_ALGORITHM`</span></a> 设置为 <code class="docutils literal notranslate"><span class="pre">'sha1'</span></code>，以便与旧版本的 Django 兼容。请注意，这需要 Django 3.1.1+。一旦过渡到 3.1，你可以停止覆盖 <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_HASHING_ALGORITHM"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code></a>。</p>
<p>因为在 Django 4.0 中，对使用 SHA-1 算法的令牌、cookie、会话和签名的支持将被取消，所以这个配置从这个版本开始就被取消了。</p>
</div>
<div class="section" id="s-minor-features">
<span id="minor-features"></span><h3>次要特性<a class="headerlink" href="#minor-features" title="永久链接至标题">¶</a></h3>
<div class="section" id="s-django-contrib-admin">
<span id="django-contrib-admin"></span><h4><a class="reference internal" href="../ref/contrib/admin/index.html#module-django.contrib.admin" title="django.contrib.admin: Django's admin site."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a><a class="headerlink" href="#django-contrib-admin" title="永久链接至标题">¶</a></h4>
<ul>
<li><p class="first">新的 <code class="docutils literal notranslate"><span class="pre">django.contrib.admin.EmptyFieldListFilter</span></code> 为 <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.list_filter" title="django.contrib.admin.ModelAdmin.list_filter"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelAdmin.list_filter</span></code></a> 允许在管理的变更列表视图中过滤空值（空字符串和空值）。</p>
</li>
<li><p class="first">管理员更改列表视图右侧的过滤器现在包含一个清除所有过滤器的链接。</p>
</li>
<li><p class="first">管理员现在在大屏幕上有一个侧栏，以便于导航。它是默认启用的，但可以通过使用一个自定义的 <code class="docutils literal notranslate"><span class="pre">AdminSite</span></code> 和设置 <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.AdminSite.enable_nav_sidebar" title="django.contrib.admin.AdminSite.enable_nav_sidebar"><code class="xref py py-attr docutils literal notranslate"><span class="pre">AdminSite.enable_nav_sidebar</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 来禁用。</p>
<p>渲染侧边栏需要访问当前请求，以便设置 CSS 和 ARIA 角色的负担。这就需要使用 <a class="reference internal" href="../ref/settings.html#std:setting-TEMPLATES-OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">OPTIONS</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">'context_processors'</span></code> 选项中的 <code class="docutils literal notranslate"><span class="pre">'django.template.context_processors.request'</span></code>。</p>
</li>
<li><p class="first">最初的空 <code class="docutils literal notranslate"><span class="pre">extra</span></code> 内联现在可以被删除，与动态创建的内联相同。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">XRegExp</span></code> 从 2.0.0 版本升级到 3.2.0。</p>
</li>
<li><p class="first">jQuery 从 3.4.1 版本升级到 3.5.1。</p>
</li>
<li><p class="first">Select2 库从 4.0.7 版本升级到 4.0.13。</p>
</li>
</ul>
</div>
<div class="section" id="s-django-contrib-auth">
<span id="django-contrib-auth"></span><h4><a class="reference internal" href="../topics/auth/index.html#module-django.contrib.auth" title="django.contrib.auth: Django's authentication framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a><a class="headerlink" href="#django-contrib-auth" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>PBKDF2 密码哈希的默认迭代次数从 180,000 增加到 216,000。</li>
<li>新的 <a class="reference internal" href="../ref/settings.html#std:setting-PASSWORD_RESET_TIMEOUT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT</span></code></a> 配置允许定义密码重置链接的有效秒数。我们鼓励这样做，而不是使用被废弃的 <code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT_DAYS</span></code> 配置，后者将在 Django 4.0 中被删除。</li>
<li>密码重置机制现在使用 SHA-256 散列算法。在 Django 4.0 之前，对使用旧的散列算法的令牌的支持仍然存在。</li>
<li><a class="reference internal" href="../topics/auth/customizing.html#django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash" title="django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AbstractBaseUser.get_session_auth_hash()</span></code></a> 现在使用 SHA-256 散列算法。在 Django 4.0 之前，对使用旧的散列算法的用户会话的支持仍然存在。</li>
</ul>
</div>
<div class="section" id="s-django-contrib-contenttypes">
<span id="django-contrib-contenttypes"></span><h4><a class="reference internal" href="../ref/contrib/contenttypes.html#module-django.contrib.contenttypes" title="django.contrib.contenttypes: Provides generic interface to installed models."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.contenttypes</span></code></a><a class="headerlink" href="#django-contrib-contenttypes" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>新的 <a class="reference internal" href="../ref/django-admin.html#cmdoption-remove-stale-contenttypes-include-stale-apps"><code class="xref std std-option docutils literal notranslate"><span class="pre">remove_stale_contenttypes</span> <span class="pre">--include-stale-apps</span></code></a> 选项允许从以前安装的应用程序中删除陈旧的内容类型，这些应用程序已经从 <a class="reference internal" href="../ref/settings.html#std:setting-INSTALLED_APPS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">INSTALLED_APPS</span></code></a> 中删除。</li>
</ul>
</div>
<div class="section" id="s-django-contrib-gis">
<span id="django-contrib-gis"></span><h4><a class="reference internal" href="../ref/contrib/gis/index.html#module-django.contrib.gis" title="django.contrib.gis: Geographic Information System (GIS) extensions for Django"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a><a class="headerlink" href="#django-contrib-gis" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/contrib/gis/geoquerysets.html#std:fieldlookup-relate"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">relate</span></code></a> 查找现已在 MariaDB 上支持。</li>
<li>添加了 <a class="reference internal" href="../ref/contrib/gis/geos.html#django.contrib.gis.geos.LinearRing.is_counterclockwise" title="django.contrib.gis.geos.LinearRing.is_counterclockwise"><code class="xref py py-attr docutils literal notranslate"><span class="pre">LinearRing.is_counterclockwise</span></code></a> 属性。</li>
<li><code class="xref py py-class docutils literal notranslate"><span class="pre">AsGeoJSON</span></code> 现已在 Oracle 上支持。</li>
<li>添加了 <code class="xref py py-class docutils literal notranslate"><span class="pre">AsWKB</span></code> 和 <code class="xref py py-class docutils literal notranslate"><span class="pre">AsWKT</span></code> 函数。</li>
<li>增加了对 PostGIS 3 和 GDAL 3 的支持。</li>
</ul>
</div>
<div class="section" id="s-django-contrib-humanize">
<span id="django-contrib-humanize"></span><h4><a class="reference internal" href="../ref/contrib/humanize.html#module-django.contrib.humanize" title="django.contrib.humanize: A set of Django template filters useful for adding a &quot;human touch&quot; to data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.humanize</span></code></a><a class="headerlink" href="#django-contrib-humanize" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/contrib/humanize.html#std:templatefilter-intword"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">intword</span></code></a> 模板过滤器现在支持负整数。</li>
</ul>
</div>
<div class="section" id="s-django-contrib-postgres">
<span id="django-contrib-postgres"></span><h4><a class="reference internal" href="../ref/contrib/postgres/index.html#module-django.contrib.postgres" title="django.contrib.postgres: PostgreSQL-specific fields and features"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.postgres</span></code></a><a class="headerlink" href="#django-contrib-postgres" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>新的 <a class="reference internal" href="../ref/contrib/postgres/indexes.html#django.contrib.postgres.indexes.BloomIndex" title="django.contrib.postgres.indexes.BloomIndex"><code class="xref py py-class docutils literal notranslate"><span class="pre">BloomIndex</span></code></a> 类允许在数据库中创建 <code class="docutils literal notranslate"><span class="pre">bloom</span></code> 索引。新的 <a class="reference internal" href="../ref/contrib/postgres/operations.html#django.contrib.postgres.operations.BloomExtension" title="django.contrib.postgres.operations.BloomExtension"><code class="xref py py-class docutils literal notranslate"><span class="pre">BloomExtension</span></code></a> 迁移操作安装 <code class="docutils literal notranslate"><span class="pre">bloom</span></code> 扩展来增加对该索引的支持。</li>
<li><a class="reference internal" href="../ref/models/instances.html#django.db.models.Model.get_FOO_display" title="django.db.models.Model.get_FOO_display"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_FOO_display()</span></code></a> 现在支持 <code class="xref py py-class docutils literal notranslate"><span class="pre">ArrayField</span></code> 和 <code class="xref py py-class docutils literal notranslate"><span class="pre">RangeField</span></code>。</li>
<li>新的 <a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.lower_inc"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.lower_inc</span></code></a>, <a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.lower_inf"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.lower_inf</span></code></a>、<a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.upper_inc"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.upper_inc</span></code></a> 和 <a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.upper_inf"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.upper_inf</span></code></a> 查找允许通过绑定类型查询 <code class="xref py py-class docutils literal notranslate"><span class="pre">RangeField</span></code>。</li>
<li><a class="reference internal" href="../ref/contrib/postgres/fields.html#std:fieldlookup-rangefield.contained_by"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">rangefield.contained_by</span></code></a> 现在支持 <a class="reference internal" href="../ref/models/fields.html#django.db.models.SmallAutoField" title="django.db.models.SmallAutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SmallAutoField</span></code></a>、<a class="reference internal" href="../ref/models/fields.html#django.db.models.AutoField" title="django.db.models.AutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">AutoField</span></code></a>、<a class="reference internal" href="../ref/models/fields.html#django.db.models.BigAutoField" title="django.db.models.BigAutoField"><code class="xref py py-class docutils literal notranslate"><span class="pre">BigAutoField</span></code></a>、<a class="reference internal" href="../ref/models/fields.html#django.db.models.SmallIntegerField" title="django.db.models.SmallIntegerField"><code class="xref py py-class docutils literal notranslate"><span class="pre">SmallIntegerField</span></code></a> 和 <a class="reference internal" href="../ref/models/fields.html#django.db.models.DecimalField" title="django.db.models.DecimalField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DecimalField</span></code></a>。</li>
<li><a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchQuery" title="django.contrib.postgres.search.SearchQuery"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchQuery</span></code></a> 现在支持 PostgreSQL 11+ 上的 <code class="docutils literal notranslate"><span class="pre">'websearch'</span></code> 搜索类型。</li>
<li><a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchQuery" title="django.contrib.postgres.search.SearchQuery"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchQuery.value</span></code></a> 现在支持查询表达式。</li>
<li>新的 <a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchHeadline" title="django.contrib.postgres.search.SearchHeadline"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchHeadline</span></code></a> 类可以高亮显示搜索结果。</li>
<li><a class="reference internal" href="../ref/contrib/postgres/search.html#std:fieldlookup-search"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">search</span></code></a> 查找现在支持查询表达式。</li>
<li>新的 <a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchRank" title="django.contrib.postgres.search.SearchRank"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchRank</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">cover_density</span></code> 参数允许按覆盖密度进行排名。</li>
<li><a class="reference internal" href="../ref/contrib/postgres/search.html#django.contrib.postgres.search.SearchRank" title="django.contrib.postgres.search.SearchRank"><code class="xref py py-class docutils literal notranslate"><span class="pre">SearchRank</span></code></a> 的新 <code class="docutils literal notranslate"><span class="pre">normalization</span></code> 参数允许进行排名规范化。</li>
<li>新的 <a class="reference internal" href="../ref/contrib/postgres/constraints.html#django.contrib.postgres.constraints.ExclusionConstraint.deferrable" title="django.contrib.postgres.constraints.ExclusionConstraint.deferrable"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ExclusionConstraint.deferrable</span></code></a> 属性允许创建可推迟的排除约束。</li>
</ul>
</div>
<div class="section" id="s-django-contrib-sessions">
<span id="django-contrib-sessions"></span><h4><a class="reference internal" href="../topics/http/sessions.html#module-django.contrib.sessions" title="django.contrib.sessions: Provides session management for Django projects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a><a class="headerlink" href="#django-contrib-sessions" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/settings.html#std:setting-SESSION_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a> 配置现在允许 <code class="docutils literal notranslate"><span class="pre">'None'</span></code> （字符串）值明确表示所有同站和跨站请求都会发送 cookie。</li>
</ul>
</div>
<div class="section" id="s-django-contrib-staticfiles">
<span id="django-contrib-staticfiles"></span><h4><a class="reference internal" href="../ref/contrib/staticfiles.html#module-django.contrib.staticfiles" title="django.contrib.staticfiles: An app for handling static files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code></a><a class="headerlink" href="#django-contrib-staticfiles" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/settings.html#std:setting-STATICFILES_DIRS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATICFILES_DIRS</span></code></a> 配置现在支持 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>。</li>
</ul>
</div>
<div class="section" id="s-cache">
<span id="cache"></span><h4>缓存<a class="headerlink" href="#cache" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>根据 <span class="target" id="index-2"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc7234.html#section-5.2.2.2"><strong>RFC 7234#section-5.2.2.2</strong></a>，<a class="reference internal" href="../topics/http/decorators.html#django.views.decorators.cache.cache_control" title="django.views.decorators.cache.cache_control"><code class="xref py py-func docutils literal notranslate"><span class="pre">cache_control()</span></code></a> 装饰器和 <a class="reference internal" href="../ref/utils.html#django.utils.cache.patch_cache_control" title="django.utils.cache.patch_cache_control"><code class="xref py py-func docutils literal notranslate"><span class="pre">patch_cache_control()</span></code></a> 方法现在支持 <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> 头的 <code class="docutils literal notranslate"><span class="pre">no-cache</span></code> 指令中的多个字段名。</li>
<li><a class="reference internal" href="../topics/cache.html#django.core.caches.cache.delete" title="django.core.caches.cache.delete"><code class="xref py py-meth docutils literal notranslate"><span class="pre">delete()</span></code></a> 现在如果键被成功删除，返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>，否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</li>
</ul>
</div>
<div class="section" id="s-csrf">
<span id="csrf"></span><h4>CSRF<a class="headerlink" href="#csrf" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/settings.html#std:setting-CSRF_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span></code></a> 配置现在允许 <code class="docutils literal notranslate"><span class="pre">'None'</span></code> （字符串）值来明确说明所有同站和跨站请求都会发送 cookie。</li>
</ul>
</div>
<div class="section" id="s-email">
<span id="email"></span><h4>电子邮件<a class="headerlink" href="#email" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../topics/email.html#topic-email-file-backend"><span class="std std-ref">附件邮件后端</span></a> 使用的 <a class="reference internal" href="../ref/settings.html#std:setting-EMAIL_FILE_PATH"><code class="xref std std-setting docutils literal notranslate"><span class="pre">EMAIL_FILE_PATH</span></code></a> 配置，现在支持 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>。</li>
</ul>
</div>
<div class="section" id="s-error-reporting">
<span id="error-reporting"></span><h4>错误报告<a class="headerlink" href="#error-reporting" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><code class="xref py py-class docutils literal notranslate"><span class="pre">django.view.debug.SafeExceptionReporterFilter</span></code> 现在可以过滤异常报告中 <code class="docutils literal notranslate"><span class="pre">request.META</span></code> 中的敏感值。</li>
<li>新的 <a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter.cleansed_substitute" title="django.views.debug.SafeExceptionReporterFilter.cleansed_substitute"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SafeExceptionReporterFilter.cleansed_substitute</span></code></a> 和 <a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter.hidden_settings" title="django.views.debug.SafeExceptionReporterFilter.hidden_settings"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SafeExceptionReporterFilter.hidden_settings</span></code></a> 属性允许在异常报告中自定义敏感配置和 <code class="docutils literal notranslate"><span class="pre">request.META</span></code> 过滤。</li>
<li>在应用配置过滤时，技术 404 调试视图现在尊重 <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_EXCEPTION_REPORTER_FILTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a>。</li>
<li>新的 <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_EXCEPTION_REPORTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER</span></code></a> 允许提供 <a class="reference internal" href="../howto/error-reporting.html#django.views.debug.ExceptionReporter" title="django.views.debug.ExceptionReporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.debug.ExceptionReporter</span></code></a> 子类来定制异常报告的生成。详情请参见 <a class="reference internal" href="../howto/error-reporting.html#custom-error-reports"><span class="std std-ref">自定义错误报告</span></a>。</li>
</ul>
</div>
<div class="section" id="s-file-storage">
<span id="file-storage"></span><h4>文件存储<a class="headerlink" href="#file-storage" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">FileSystemStorage.save()</span></code> 方法现在支持 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>。</li>
<li><a class="reference internal" href="../ref/models/fields.html#django.db.models.FileField" title="django.db.models.FileField"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileField</span></code></a> 和 <a class="reference internal" href="../ref/models/fields.html#django.db.models.ImageField" title="django.db.models.ImageField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ImageField</span></code></a> 现在可以接受 <code class="docutils literal notranslate"><span class="pre">storage</span></code> 的调用。这允许你在运行时修改所使用的存储，例如为不同的环境选择不同的存储。</li>
</ul>
</div>
<div class="section" id="s-forms">
<span id="forms"></span><h4>表单<a class="headerlink" href="#forms" title="永久链接至标题">¶</a></h4>
<ul>
<li><p class="first"><a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIterator" title="django.forms.ModelChoiceIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIterator</span></code></a>，被 <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceField" title="django.forms.ModelChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField</span></code></a> 和 <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelMultipleChoiceField" title="django.forms.ModelMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a> 使用，现在使用 <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIteratorValue" title="django.forms.ModelChoiceIteratorValue"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIteratorValue</span></code></a>，可以被部件用来访问模型实例。详情请看 <a class="reference internal" href="../ref/forms/fields.html#iterating-relationship-choices"><span class="std std-ref">迭代关系选择</span></a>。</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/forms/fields.html#django.forms.DateTimeField" title="django.forms.DateTimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.forms.DateTimeField</span></code></a> 现在接受 ISO 8601 日期时间格式的子集，包括可选的时区，例如 <code class="docutils literal notranslate"><span class="pre">2019-10-10T06:47</span></code>、<code class="docutils literal notranslate"><span class="pre">2019-10-10T06:47:23+04:00</span></code> 或 <code class="docutils literal notranslate"><span class="pre">2019-10-10T06:47:23Z</span></code>。如果提供了时区，将始终保留时区，即使 <a class="reference internal" href="../ref/settings.html#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 时，也会返回时区感知的日期时间。</p>
<p>此外，<code class="docutils literal notranslate"><span class="pre">DateTimeField</span></code> 现在在将字段输入转换为 <code class="docutils literal notranslate"><span class="pre">datetime</span></code> 值时，除了使用 <code class="docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code> 外，还使用 <code class="docutils literal notranslate"><span class="pre">DATE_INPUT_FORMATS</span></code>。</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/forms/widgets.html#django.forms.MultiWidget.widgets" title="django.forms.MultiWidget.widgets"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MultiWidget.widgets</span></code></a> 现在接受一个字典，允许自定义子部件 <code class="docutils literal notranslate"><span class="pre">name</span></code> 属性。</p>
</li>
<li><p class="first">新的 <a class="reference internal" href="../ref/forms/api.html#django.forms.BoundField.widget_type" title="django.forms.BoundField.widget_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">BoundField.widget_type</span></code></a> 属性可用于根据部件类型动态调整表单渲染。</p>
</li>
</ul>
</div>
<div class="section" id="s-internationalization">
<span id="internationalization"></span><h4>国际化<a class="headerlink" href="#internationalization" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/settings.html#std:setting-LANGUAGE_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">LANGUAGE_COOKIE_SAMESITE</span></code></a> 配置现在允许 <code class="docutils literal notranslate"><span class="pre">'None'</span></code> （字符串）值明确表示所有同站和跨站请求都会发送 cookie。</li>
<li>增加了对阿尔及利亚阿拉伯语、伊博语、吉尔吉斯语、塔吉克语和土库曼语的支持和翻译。</li>
</ul>
</div>
<div class="section" id="s-management-commands">
<span id="management-commands"></span><h4>管理命令<a class="headerlink" href="#management-commands" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>新的 <a class="reference internal" href="../ref/django-admin.html#cmdoption-check-database"><code class="xref std std-option docutils literal notranslate"><span class="pre">check</span> <span class="pre">--database</span></code></a> 选项允许指定数据库别名，以便运行 <code class="docutils literal notranslate"><span class="pre">database</span></code> 系统检查。以前，通过向命令传递 <code class="docutils literal notranslate"><span class="pre">database</span></code> 标签，为所有设置的 <a class="reference internal" href="../ref/settings.html#std:setting-DATABASES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATABASES</span></code></a> 启用这些检查。</li>
<li>新的 <a class="reference internal" href="../ref/django-admin.html#cmdoption-migrate-check"><code class="xref std std-option docutils literal notranslate"><span class="pre">migrate</span> <span class="pre">--check</span></code></a> 选项使命令在检测到未应用的迁移时以非零状态退出。</li>
<li><a class="reference internal" href="../howto/custom-management-commands.html#django.core.management.CommandError" title="django.core.management.CommandError"><code class="xref py py-attr docutils literal notranslate"><span class="pre">CommandError</span></code></a> 的新 <a href="#id1"><span class="problematic" id="id2">``</span></a>returncode``参数允许自定义管理命令的退出状态。</li>
<li>新的 <a class="reference internal" href="../ref/django-admin.html#cmdoption-dbshell"><code class="xref std std-option docutils literal notranslate"><span class="pre">dbshell</span> <span class="pre">--</span> <span class="pre">ARGUMENTS</span></code></a> 选项允许向数据库的命令行客户端传递额外的参数。</li>
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-flush"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">flush</span></code></a> 和 <a class="reference internal" href="../ref/django-admin.html#django-admin-sqlflush"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">sqlflush</span></code></a> 命令现在包括 SQL 来重置 SQLite 上的序列。</li>
</ul>
</div>
<div class="section" id="s-models">
<span id="models"></span><h4>模型<a class="headerlink" href="#models" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>新的 <code class="xref py py-class docutils literal notranslate"><span class="pre">ExtractIsoWeekDay</span></code> 函数从 <a class="reference internal" href="../ref/models/fields.html#django.db.models.DateField" title="django.db.models.DateField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateField</span></code></a> 和 <a class="reference internal" href="../ref/models/fields.html#django.db.models.DateTimeField" title="django.db.models.DateTimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateTimeField</span></code></a> 中提取 ISO-8601 周天，新的 <a class="reference internal" href="../ref/models/querysets.html#std:fieldlookup-iso_week_day"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">iso_week_day</span></code></a> 查询可以按 ISO-8601 周天查询。</li>
<li><a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.explain" title="django.db.models.query.QuerySet.explain"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.explain()</span></code></a> 现在支持：<ul>
<li>MySQL 8.0.16+ 上的 <code class="docutils literal notranslate"><span class="pre">TREE</span></code> 格式，</li>
<li>MySQL 8.0.18+ 和 MariaDB 上的 <code class="docutils literal notranslate"><span class="pre">analyze</span></code> 选项。</li>
</ul>
</li>
<li>添加了 <a class="reference internal" href="../ref/models/fields.html#django.db.models.PositiveBigIntegerField" title="django.db.models.PositiveBigIntegerField"><code class="xref py py-class docutils literal notranslate"><span class="pre">PositiveBigIntegerField</span></code></a>，它的作用很像 <a class="reference internal" href="../ref/models/fields.html#django.db.models.PositiveIntegerField" title="django.db.models.PositiveIntegerField"><code class="xref py py-class docutils literal notranslate"><span class="pre">PositiveIntegerField</span></code></a>，只是它只允许在一定（依赖于数据库的）限制下取值。从 <code class="docutils literal notranslate"><span class="pre">0</span></code> 到 <code class="docutils literal notranslate"><span class="pre">9223372036854775807</span></code> 的值在 Django 支持的所有数据库中都是安全的。</li>
<li>新的 <a class="reference internal" href="../ref/models/fields.html#django.db.models.RESTRICT" title="django.db.models.RESTRICT"><code class="xref py py-class docutils literal notranslate"><span class="pre">RESTRICT</span></code></a> 选项为 <code class="xref py py-attr docutils literal notranslate"><span class="pre">ForeignKey`</span></code> 和 <code class="docutils literal notranslate"><span class="pre">OneToOneField</span></code> 的 <a class="reference internal" href="../ref/models/fields.html#django.db.models.ForeignKey.on_delete" title="django.db.models.ForeignKey.on_delete"><code class="xref py py-attr docutils literal notranslate"><span class="pre">on_delete</span></code></a> 参数模拟了 SQL 约束 <code class="docutils literal notranslate"><span class="pre">ON</span> <span class="pre">DELETE</span> <span class="pre">RESTRICT</span></code> 的行为。</li>
<li><a class="reference internal" href="../ref/models/constraints.html#django.db.models.CheckConstraint.check" title="django.db.models.CheckConstraint.check"><code class="xref py py-attr docutils literal notranslate"><span class="pre">CheckConstraint.check</span></code></a> 现在支持布尔表达式。</li>
<li><a class="reference internal" href="../ref/models/relations.html#django.db.models.fields.related.RelatedManager.add" title="django.db.models.fields.related.RelatedManager.add"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RelatedManager.add()</span></code></a>、<a class="reference internal" href="../ref/models/relations.html#django.db.models.fields.related.RelatedManager.create" title="django.db.models.fields.related.RelatedManager.create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create()</span></code></a> 和 <a class="reference internal" href="../ref/models/relations.html#django.db.models.fields.related.RelatedManager.set" title="django.db.models.fields.related.RelatedManager.set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set()</span></code></a> 方法现在接受可调用对象参数作为 <code class="docutils literal notranslate"><span class="pre">through_defaults</span></code> 参数的值。</li>
<li><a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.datetimes" title="django.db.models.query.QuerySet.datetimes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.datetimes()</span></code></a> 的新 <code class="docutils literal notranslate"><span class="pre">is_dst</span></code> 参数决定了如何处理不存在和不明确的日期。</li>
<li>新的 <a class="reference internal" href="../ref/models/expressions.html#django.db.models.F" title="django.db.models.F"><code class="xref py py-class docutils literal notranslate"><span class="pre">F</span></code></a> 表达式 <code class="docutils literal notranslate"><span class="pre">bitxor()</span></code> 方法允许 <a class="reference internal" href="../topics/db/queries.html#using-f-expressions-in-filters"><span class="std std-ref">bitwise XOR 操作</span></a>。</li>
<li><a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.bulk_create" title="django.db.models.query.QuerySet.bulk_create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.bulk_create()</span></code></a> 在使用 MariaDB 10.5+ 时，现在可以设置对象的主键。</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.sql_flush()</span></code> 方法现在可以在 MySQL 上生成更有效的 SQL，对于不需要重置序列的表，使用 <code class="docutils literal notranslate"><span class="pre">DELETE</span></code> 而不是 <code class="docutils literal notranslate"><span class="pre">TRUNCATE</span></code> 语句。</li>
<li>SQLite 函数现已在 Python 3.8+ 上被标记为 <a class="reference external" href="https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function" title="(在 Python v3.10)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">deterministic</span></code></a>。这允许在检查约束和部分索引中使用它们。</li>
<li>新的 <a class="reference internal" href="../ref/models/constraints.html#django.db.models.UniqueConstraint.deferrable" title="django.db.models.UniqueConstraint.deferrable"><code class="xref py py-attr docutils literal notranslate"><span class="pre">UniqueConstraint.deferrable</span></code></a> 属性允许创建可推迟的唯一约束。</li>
</ul>
</div>
<div class="section" id="s-pagination">
<span id="pagination"></span><h4>分页<a class="headerlink" href="#pagination" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/paginator.html#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Paginator</span></code></a> 现在可以迭代产生其页面。</li>
</ul>
</div>
<div class="section" id="s-requests-and-responses">
<span id="requests-and-responses"></span><h4>请求和响应<a class="headerlink" href="#requests-and-responses" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>如果 <a class="reference internal" href="../ref/settings.html#std:setting-ALLOWED_HOSTS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">ALLOWED_HOSTS</span></code></a> 为空且 <code class="docutils literal notranslate"><span class="pre">DEBUG=True</span></code>，则在 <code class="docutils literal notranslate"><span class="pre">Host</span></code> 头中允许使用 localhost 的子域，例如 <code class="docutils literal notranslate"><span class="pre">static.localhost</span></code>。</li>
<li><a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse.set_cookie" title="django.http.HttpResponse.set_cookie"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpResponse.set_cookie()</span></code></a> 和 <a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse.set_signed_cookie" title="django.http.HttpResponse.set_signed_cookie"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpResponse.set_signed_cookie()</span></code></a> 现在允许使用 <code class="docutils literal notranslate"><span class="pre">samesite='None'</span></code> （字符串）来明确说明所有同站和跨站请求都会发送cookie。</li>
<li>新的 <a class="reference internal" href="../ref/request-response.html#django.http.HttpRequest.accepts" title="django.http.HttpRequest.accepts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpRequest.accepts()</span></code></a> 方法根据 <code class="docutils literal notranslate"><span class="pre">Accept</span></code> HTTP 头返回请求是否接受给定的 MIME 类型。</li>
</ul>
</div>
<div class="section" id="s-security">
<span id="s-whats-new-security-3-1"></span><span id="security"></span><span id="whats-new-security-3-1"></span><h4>安全<a class="headerlink" href="#security" title="永久链接至标题">¶</a></h4>
<ul>
<li><p class="first"><a class="reference internal" href="../ref/settings.html#std:setting-SECURE_REFERRER_POLICY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a> 配置现在默认为 <code class="docutils literal notranslate"><span class="pre">'same-origin'</span></code>。设置了这个之后，<a class="reference internal" href="../ref/middleware.html#django.middleware.security.SecurityMiddleware" title="django.middleware.security.SecurityMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecurityMiddleware</span></code></a> 会在所有还没有设置 <a class="reference internal" href="../ref/middleware.html#referrer-policy"><span class="std std-ref">Referrer 政策</span></a> 头的情况下，将其设置为 <code class="docutils literal notranslate"><span class="pre">same-origin</span></code>。这可以防止 <code class="docutils literal notranslate"><span class="pre">Referer</span></code> 头被发送到其他来源。如果你需要以前的行为，明确地设置 <a class="reference internal" href="../ref/settings.html#std:setting-SECURE_REFERRER_POLICY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
</li>
<li><p class="first"><a class="reference internal" href="../topics/signing.html#django.core.signing.Signer" title="django.core.signing.Signer"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.core.signing.Signer</span></code></a>、<code class="xref py py-meth docutils literal notranslate"><span class="pre">django.core.signing.load()</span></code> 和 <a class="reference internal" href="../topics/signing.html#django.core.signing.dumps" title="django.core.signing.dumps"><code class="xref py py-meth docutils literal notranslate"><span class="pre">django.core.signing.dumps()</span></code></a> 的默认算法改为 SHA-256。在 Django 4.0 之前，仍然支持用旧的 SHA-1 算法进行签名。</p>
<p>另外，<a class="reference internal" href="../topics/signing.html#django.core.signing.Signer" title="django.core.signing.Signer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signer</span></code></a> 的新 <code class="docutils literal notranslate"><span class="pre">algorithm</span></code> 参数允许自定义哈希算法。</p>
</li>
</ul>
</div>
<div class="section" id="s-templates">
<span id="templates"></span><h4>模板<a class="headerlink" href="#templates" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>重新命名的 <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-translate"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">translate</span></code></a> 和 <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-blocktranslate"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">blocktranslate</span></code></a> 模板标签被引入，用于模板代码的国际化。旧的 <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-trans"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">trans</span></code></a> 和 <a class="reference internal" href="../topics/i18n/translation.html#std:templatetag-blocktrans"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">blocktrans</span></code></a> 模板标签的别名继续工作，并将在可预见的未来保留。</li>
<li><a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-include"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">include</span></code></a> 模板标签现在接受模板名称的可迭代对象。</li>
</ul>
</div>
<div class="section" id="s-tests">
<span id="tests"></span><h4>测试<a class="headerlink" href="#tests" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../topics/testing/tools.html#django.test.SimpleTestCase" title="django.test.SimpleTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleTestCase</span></code></a> 现在实现了 <code class="docutils literal notranslate"><span class="pre">debug()</span></code> 方法，允许在不收集结果和捕获异常的情况下运行测试。这可以用来支持在调试器下运行测试。</li>
<li>新的 <a class="reference internal" href="../ref/settings.html#std:setting-TEST_MIGRATE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MIGRATE</span></code></a> 测试数据库配置允许在创建测试数据库时禁止迁移。</li>
<li>Django 测试运行器现在支持 <a class="reference internal" href="../ref/django-admin.html#cmdoption-test-buffer"><code class="xref std std-option docutils literal notranslate"><span class="pre">test</span> <span class="pre">--buffer</span></code></a> 选项，以丢弃通过测试的输出。</li>
<li><a class="reference internal" href="../topics/testing/advanced.html#django.test.runner.DiscoverRunner" title="django.test.runner.DiscoverRunner"><code class="xref py py-class docutils literal notranslate"><span class="pre">DiscoverRunner</span></code></a> 现在会跳过对非 <a class="reference internal" href="../topics/testing/tools.html#testing-multi-db"><span class="std std-ref">测试所引用</span></a> 的数据库进行系统检查。</li>
<li><a class="reference internal" href="../topics/testing/tools.html#django.test.TransactionTestCase" title="django.test.TransactionTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">TransactionTestCase</span></code></a> 关闭现在在 MySQL 上的速度更快了，这是因为 <a class="reference internal" href="../ref/django-admin.html#django-admin-flush"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">flush</span></code></a> 命令的改进。作为一个副作用，后者不会再在关闭时自动重置序列。如果你的测试需要这个功能，请启用 <a class="reference internal" href="../topics/testing/advanced.html#django.test.TransactionTestCase.reset_sequences" title="django.test.TransactionTestCase.reset_sequences"><code class="xref py py-attr docutils literal notranslate"><span class="pre">TransactionTestCase.reset_sequences</span></code></a>。</li>
</ul>
</div>
<div class="section" id="s-urls">
<span id="urls"></span><h4>URLs<a class="headerlink" href="#urls" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../topics/http/urls.html#registering-custom-path-converters"><span class="std std-ref">Path 转换器</span></a> 现在可以在 <code class="docutils literal notranslate"><span class="pre">to_url()</span></code> 中引发 <code class="docutils literal notranslate"><span class="pre">ValueError</span></code>，在反查 URL 时表示不匹配。</li>
</ul>
</div>
<div class="section" id="s-utilities">
<span id="utilities"></span><h4>实用程序<a class="headerlink" href="#utilities" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/utils.html#django.utils.encoding.filepath_to_uri" title="django.utils.encoding.filepath_to_uri"><code class="xref py py-func docutils literal notranslate"><span class="pre">filepath_to_uri()</span></code></a> 现在支持 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>。</li>
<li><a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_duration" title="django.utils.dateparse.parse_duration"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_duration()</span></code></a> 现在支持 ISO 8601 格式的小数点用逗号分隔。</li>
<li><a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_datetime" title="django.utils.dateparse.parse_datetime"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_datetime()</span></code></a>、<a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_duration" title="django.utils.dateparse.parse_duration"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_duration()</span></code></a> 和 <a class="reference internal" href="../ref/utils.html#django.utils.dateparse.parse_time" title="django.utils.dateparse.parse_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_time()</span></code></a> 现在支持用逗号分隔毫秒。</li>
</ul>
</div>
<div class="section" id="s-miscellaneous">
<span id="miscellaneous"></span><h4>杂项<a class="headerlink" href="#miscellaneous" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>SQLite 后端现在支持 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">NAME</span></code> 的配置。</li>
<li>由 <a class="reference internal" href="../ref/django-admin.html#django-admin-startproject"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">startproject</span></code></a> 命令生成的 <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> 现在使用 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.10)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> 代替 <a class="reference external" href="https://docs.python.org/3/library/os.path.html#module-os.path" title="(在 Python v3.10)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> 来建立文件系统路径。</li>
<li>现在允许在支持时区的数据库上进行 <a class="reference internal" href="../ref/settings.html#std:setting-DATABASE-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a> 设置。</li>
</ul>
</div>
</div>
</div>
<div class="section" id="s-backwards-incompatible-changes-in-3-1">
<span id="s-backwards-incompatible-3-1"></span><span id="backwards-incompatible-changes-in-3-1"></span><span id="backwards-incompatible-3-1"></span><h2>3.1 中的不向后兼容的变更<a class="headerlink" href="#backwards-incompatible-changes-in-3-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-database-backend-api">
<span id="database-backend-api"></span><h3>数据库后端 API<a class="headerlink" href="#database-backend-api" title="永久链接至标题">¶</a></h3>
<p>本节介绍了第三方数据库后端可能需要的更改。</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.fetch_returned_insert_columns()</span></code> 现在需要一个额外的 <code class="docutils literal notranslate"><span class="pre">returning_params</span></code> 参数。</li>
<li><code class="docutils literal notranslate"><span class="pre">connection.timezone</span></code> 属性现在默认为 <code class="docutils literal notranslate"><span class="pre">'UTC</span></code>，或者当 <a class="reference internal" href="../ref/settings.html#std:setting-USE_TZ"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_TZ</span></code></a> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 时，支持时区的数据库上的 <a class="reference internal" href="../ref/settings.html#std:setting-DATABASE-TIME_ZONE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">TIME_ZONE</span></code></a>。此前，在支持时区的数据库上是 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</li>
<li><code class="docutils literal notranslate"><span class="pre">connection._nodb_connection</span></code> 属性改为 <code class="docutils literal notranslate"><span class="pre">connection._nodb_cursor()</span></code> 方法，现在返回一个产生游标的上下文管理器，并在退出 <code class="docutils literal notranslate"><span class="pre">with</span></code> 语句后自动关闭游标和连接。</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseClient.runshell()</span></code> 现在需要一个额外的 <code class="docutils literal notranslate"><span class="pre">parameters</span></code> 参数，作为传递给命令行客户端的额外参数列表。</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.sql_flush()</span></code> 的 <code class="docutils literal notranslate"><span class="pre">sequences</span></code> 位置参数被只用关键字的布尔参数 <code class="docutils literal notranslate"><span class="pre">reset_sequences</span></code> 取代。如果 <code class="docutils literal notranslate"><span class="pre">True</span></code>，截断表的序列将被重置。</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.sql_flush()</span></code> 的 <code class="docutils literal notranslate"><span class="pre">allow_cascade</span></code> 参数现在是一个纯关键字的参数。</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.execute_sql_flush()</span></code> 的 <code class="docutils literal notranslate"><span class="pre">using</span></code> 位置参数被删除。该方法现在使用被调用实例的数据库。</li>
<li>第三方数据库后端必须实现对 <code class="docutils literal notranslate"><span class="pre">JSONField</span></code> 的支持，或者将 <code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.supports_json_field</span></code> 设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。如果不支持存储基元，则设置 <code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.supports_primitives_in_json_field</span></code> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。如果 JSON 的数据类型为真，则设置 <code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.has_native_json_field</span></code> 为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。如果不支持 <a class="reference internal" href="../topics/db/queries.html#std:fieldlookup-jsonfield.contains"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">jsonfield.contains</span></code></a> 和 <code class="xref std std-lookup docutils literal notranslate"><span class="pre">jsonfield.contains_by</span></code>，则将 <code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.support_json_field_contains</span></code> 设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</li>
<li>第三方数据库后端必须实现对 <code class="docutils literal notranslate"><span class="pre">JSONField</span></code> 的自省，或者将 <code class="docutils literal notranslate"><span class="pre">can_introspect_json_field</span></code> 设置为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</li>
</ul>
</div>
<div class="section" id="s-dropped-support-for-mariadb-10-1">
<span id="dropped-support-for-mariadb-10-1"></span><h3>丢弃了对 MariaDB 10.1 的支持<a class="headerlink" href="#dropped-support-for-mariadb-10-1" title="永久链接至标题">¶</a></h3>
<p>对 MariaDB 10.1 的上游支持在 2020 年 10 月结束。Django 3.1 支持 MariaDB 10.2 及以上版本。</p>
</div>
<div class="section" id="s-contrib-admin-browser-support">
<span id="contrib-admin-browser-support"></span><h3><code class="docutils literal notranslate"><span class="pre">contrib.admin</span></code> 浏览器支持<a class="headerlink" href="#contrib-admin-browser-support" title="永久链接至标题">¶</a></h3>
<p>管理不再支持传统的 Internet Explorer 浏览器。关于支持的浏览器，请参见 <a class="reference internal" href="../faq/admin.html#admin-browser-support"><span class="std std-ref">管理常见问题</span></a>。</p>
</div>
<div class="section" id="s-abstractuser-first-name-max-length-increased-to-150">
<span id="abstractuser-first-name-max-length-increased-to-150"></span><h3><a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.first_name" title="django.contrib.auth.models.User.first_name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">AbstractUser.first_name</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">max_length</span></code> 增加到 150<a class="headerlink" href="#abstractuser-first-name-max-length-increased-to-150" title="永久链接至标题">¶</a></h3>
<p>包含了 <a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.first_name" title="django.contrib.auth.models.User.first_name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">django.contrib.auth.models.User.first_name</span></code></a> 的迁移。如果你有一个继承自 <code class="docutils literal notranslate"><span class="pre">AbstractUser</span></code> 的自定义用户模型，你将需要为你的用户模型生成并应用数据库迁移。</p>
<p>如果你想保留 first name 的 30 个字符限制，请使用自定义表单：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
<span class="kn">from</span> <span class="nn">django.contrib.auth.forms</span> <span class="kn">import</span> <span class="n">UserChangeForm</span>

<span class="k">class</span> <span class="nc">MyUserChangeForm</span><span class="p">(</span><span class="n">UserChangeForm</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p>如果你想在管理中编辑用户时保留这个限制，请将 <code class="docutils literal notranslate"><span class="pre">UserAdmin.form</span></code> 设置为使用这个表单：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.auth.admin</span> <span class="kn">import</span> <span class="n">UserAdmin</span>
<span class="kn">from</span> <span class="nn">django.contrib.auth.models</span> <span class="kn">import</span> <span class="n">User</span>

<span class="k">class</span> <span class="nc">MyUserAdmin</span><span class="p">(</span><span class="n">UserAdmin</span><span class="p">):</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">MyUserChangeForm</span>

<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">unregister</span><span class="p">(</span><span class="n">User</span><span class="p">)</span>
<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">User</span><span class="p">,</span> <span class="n">MyUserAdmin</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-id1">
<span id="id1"></span><h3>杂项<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li><a class="reference internal" href="../topics/cache.html#std:templatetag-cache"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">cache</span></code></a> 使用的缓存密钥和 <a class="reference internal" href="../topics/cache.html#django.core.cache.utils.make_template_fragment_key" title="django.core.cache.utils.make_template_fragment_key"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_template_fragment_key()</span></code></a> 生成的缓存密钥与旧版本 Django 生成的密钥不同。升级到 Django 3.1 后，第一次请求任何之前缓存的模板片段都会被缓存错过。</li>
<li>从 <a class="reference internal" href="../topics/i18n/translation.html#django.views.i18n.set_language" title="django.views.i18n.set_language"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_language()</span></code></a> 视图中返回重定向回退或 204 HTTP 响应背后的逻辑现在是基于 <code class="docutils literal notranslate"><span class="pre">Accept</span></code> HTTP 头而不是 <code class="docutils literal notranslate"><span class="pre">X-Requested-With</span></code> HTTP 头的存在。</li>
<li><code class="docutils literal notranslate"><span class="pre">django.db.models.query</span></code>、<code class="docutils literal notranslate"><span class="pre">django.db.models.sql</span></code> 和 <code class="docutils literal notranslate"><span class="pre">django.db.models.sql.datastructures</span></code> 中的 <code class="docutils literal notranslate"><span class="pre">django.core.exceptions.EmptyResultSet</span></code> 的兼容性导入被移除。</li>
<li>删除了 <code class="docutils literal notranslate"><span class="pre">django.db.models.field</span></code> 中 <code class="docutils literal notranslate"><span class="pre">django.core.exceptions.FieldDoesNotExist</span></code> 的兼容性导入。</li>
<li>删除了 <code class="docutils literal notranslate"><span class="pre">django.forms.utils.pretty_name()</span></code> 和 <code class="docutils literal notranslate"><span class="pre">django.forms.boundfield.BoundField</span></code> 的兼容性导入。</li>
<li><code class="docutils literal notranslate"><span class="pre">django.template.base</span></code> 中的 <code class="docutils literal notranslate"><span class="pre">Context</span></code>、<code class="docutils literal notranslate"><span class="pre">ContextPopException</span></code> 和 <code class="docutils literal notranslate"><span class="pre">RequestContext</span></code> 的兼容性导入被移除。</li>
<li>删除了 <code class="docutils literal notranslate"><span class="pre">django.contrib.admin.helpers.ACTION_CHECKBOX_NAME</span></code> 中的兼容性导入。</li>
<li>设置为相对路径的 <a class="reference internal" href="../ref/settings.html#std:setting-STATIC_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">STATIC_URL</span></code></a> 和 <a class="reference internal" href="../ref/settings.html#std:setting-MEDIA_URL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">MEDIA_URL</span></code></a> 配置现在以服务器提供的 <code class="docutils literal notranslate"><span class="pre">SCRIPT_NAME</span></code> 的值为前缀（如果没有设置，则为 <code class="docutils literal notranslate"><span class="pre">/</span></code>）。这一变化不应影响设置为有效 URL 或绝对路径的配置。</li>
<li><a class="reference internal" href="../ref/middleware.html#django.middleware.http.ConditionalGetMiddleware" title="django.middleware.http.ConditionalGetMiddleware"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConditionalGetMiddleware</span></code></a> 不再为空 <a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse.content" title="django.http.HttpResponse.content"><code class="xref py py-attr docutils literal notranslate"><span class="pre">content</span></code></a> 的响应添加 <code class="docutils literal notranslate"><span class="pre">ETag</span></code> 头。</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.disturators.classproperty()</span></code> 装饰器被公开并移到 <a class="reference internal" href="../ref/utils.html#django.utils.functional.classproperty" title="django.utils.functional.classproperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.utils.functional.classproperty()</span></code></a>。</li>
<li><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">floatform</span></code> 模板过滤器现在对四舍五入为零的负数输出（正）``0```。</li>
<li><a class="reference internal" href="../ref/models/options.html#django.db.models.Options.ordering" title="django.db.models.Options.ordering"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Meta.ordering</span></code></a> 和 <code class="xref py py-attr docutils literal notranslate"><span class="pre">Meta.unique_together</span> <span class="pre">&lt;django.db.models.Options.unique_together&gt;`</span></code> 模块中模型的选项，以前是元组，现在是列表。</li>
<li>管理日历部件现在根据开放组规范处理两位数的年份，即 69 和 99 之间的值被映射到上一个世纪，0 和 68 之间的值被映射到当前世纪。</li>
<li>从 <a class="reference internal" href="../ref/settings.html#std:setting-DATETIME_INPUT_FORMATS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DATETIME_INPUT_FORMATS</span></code></a> 的默认列表中删除了仅限日期的格式。</li>
<li>当初始数据存在时，<a class="reference internal" href="../ref/forms/widgets.html#django.forms.FileInput" title="django.forms.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileInput</span></code></a> 小部件不再使用 <code class="docutils literal notranslate"><span class="pre">required</span></code> HTML 属性进行渲染。</li>
<li>删除了未记录的 <code class="docutils literal notranslate"><span class="pre">django.views.debug.ExceptionReporterFilter</span></code> 类。根据 <a class="reference internal" href="../howto/error-reporting.html#custom-error-reports"><span class="std std-ref">自定义错误报告</span></a> 文档，与 <a class="reference internal" href="../ref/settings.html#std:setting-DEFAULT_EXCEPTION_REPORTER_FILTER"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DEFAULT_EXCEPTION_REPORTER_FILTER</span></code></a> 一起使用的类需要继承 <a class="reference internal" href="../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter" title="django.views.debug.SafeExceptionReporterFilter"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.debug.SafeExceptionReporterFilter</span></code></a>。</li>
<li><a class="reference internal" href="../topics/cache.html#django.views.decorators.cache.cache_page" title="django.views.decorators.cache.cache_page"><code class="xref py py-func docutils literal notranslate"><span class="pre">cache_page()</span></code></a> 装饰器设置的缓存超时现在优先于 <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> 头的 <code class="docutils literal notranslate"><span class="pre">max-age</span></code> 指令。</li>
<li>在 <a class="reference internal" href="../ref/models/fields.html#django.db.models.ForeignKey.to_field" title="django.db.models.ForeignKey.to_field"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ForeignKey.to_field</span></code></a> 参数中提供一个非本地的远程字段，现在会引发 <a class="reference internal" href="../ref/exceptions.html#django.core.exceptions.FieldError" title="django.core.exceptions.FieldError"><code class="xref py py-class docutils literal notranslate"><span class="pre">FieldError</span></code></a>。</li>
<li><a class="reference internal" href="../ref/settings.html#std:setting-SECURE_REFERRER_POLICY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SECURE_REFERRER_POLICY</span></code></a> 现在默认为 <code class="docutils literal notranslate"><span class="pre">'same-origin'</span></code>。更多细节请参见 <em>新变化</em> <a class="reference internal" href="#whats-new-security-3-1"><span class="std std-ref">安全章节</span></a>。</li>
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-check"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">check</span></code></a> 管理命令现在只对使用 <a class="reference internal" href="../ref/django-admin.html#cmdoption-check-database"><code class="xref std std-option docutils literal notranslate"><span class="pre">check</span> <span class="pre">--database</span></code></a> 选项指定的数据库别名运行 <code class="docutils literal notranslate"><span class="pre">database</span></code> 系统检查。</li>
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-migrate"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">migrate</span></code></a> 管理命令现在只运行 <code class="docutils literal notranslate"><span class="pre">database</span></code> 系统检查要迁移的数据库。</li>
<li>管理 CSS 类 <code class="docutils literal notranslate"><span class="pre">row1</span></code> 和 <code class="docutils literal notranslate"><span class="pre">row2</span></code> 被删除，取而代之的是 <code class="docutils literal notranslate"><span class="pre">:nth-child(odd)</span></code> 和 <code class="docutils literal notranslate"><span class="pre">:nth-child(even)</span></code> 伪类。</li>
<li><a class="reference internal" href="../topics/auth/passwords.html#django.contrib.auth.hashers.make_password" title="django.contrib.auth.hashers.make_password"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_password()</span></code></a> 函数现在要求其参数为字符串或字节。其他类型的参数应该显式地转换为其中之一。</li>
<li>删除了 <code class="xref py py-class docutils literal notranslate"><span class="pre">AsKML</span></code> 函数中未记录的 <code class="docutils literal notranslate"><span class="pre">version</span></code> 参数。</li>
<li><a class="reference internal" href="../topics/serialization.html#serialization-formats"><span class="std std-ref">JSON 和 YAML 序列化器</span></a>，由 <a class="reference internal" href="../ref/django-admin.html#django-admin-dumpdata"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">dumpdata</span></code></a> 使用，现在默认使用 Unicode 转储所有数据。如果你需要以前的行为，传递 <code class="docutils literal notranslate"><span class="pre">ensure_ascii=True</span></code> 给 JSON 序列化器，或者 <code class="docutils literal notranslate"><span class="pre">allow_unicode=False</span></code> 给 YAML 序列化器。</li>
<li>自动重新加载器不再监控内置 Django 翻译文件的变化。</li>
<li><code class="docutils literal notranslate"><span class="pre">mysqlclient</span></code> 的最低支持版本从 1.3.13 增加到 1.4.0。</li>
<li>未记录的 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.InvalidJSONInput</span></code> 和 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.JSONString</span></code> 被移至 <code class="docutils literal notranslate"><span class="pre">django.forms.field</span></code>。</li>
<li>删除了未记录的 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.field.jsonb.JsonAdapter</span></code> 类。</li>
<li><a class="reference internal" href="../topics/i18n/formatting.html#std:templatetag-localize"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">{%</span> <span class="pre">localize</span> <span class="pre">off</span> <span class="pre">%}</span></code></a> 标签和 <a class="reference internal" href="../topics/i18n/formatting.html#std:templatefilter-unlocalize"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">unlocalize</span></code></a> 过滤器不再遵守 <a class="reference internal" href="../ref/settings.html#std:setting-DECIMAL_SEPARATOR"><code class="xref std std-setting docutils literal notranslate"><span class="pre">DECIMAL_SEPARATOR</span></code></a> 配置。</li>
<li><code class="docutils literal notranslate"><span class="pre">asgiref</span></code> 的最低支持版本从 3.2 增加到 3.2.10。</li>
<li><a class="reference internal" href="../topics/forms/media.html"><span class="doc">Media</span></a> 类现在不使用 <code class="docutils literal notranslate"><span class="pre">type</span></code> 属性来渲染 <code class="docutils literal notranslate"><span class="pre">&lt;script&gt;</span></code> 标签，以遵循 <a class="reference external" href="https://html.spec.whatwg.org/multipage/scripting.html#the-script-element">WHATWG 建议</a> 。</li>
<li><a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIterator" title="django.forms.ModelChoiceIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIterator</span></code></a>，由 <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceField" title="django.forms.ModelChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceField</span></code></a> 和 <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelMultipleChoiceField" title="django.forms.ModelMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a> 使用，现在产生 2 个包含 <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIteratorValue" title="django.forms.ModelChoiceIteratorValue"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelChoiceIteratorValue</span></code></a> 实例的选择，作为每个选择的第一个 <code class="docutils literal notranslate"><span class="pre">value</span></code> 元素。在大多数情况下，这个代理是透明的，但如果你需要 <code class="docutils literal notranslate"><span class="pre">field</span></code> 值本身，请使用 <a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelChoiceIteratorValue.value" title="django.forms.ModelChoiceIteratorValue.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelChoiceIteratorValue.value</span></code></a> 属性代替。</li>
</ul>
</div>
</div>
<div class="section" id="s-features-deprecated-in-3-1">
<span id="s-deprecated-features-3-1"></span><span id="features-deprecated-in-3-1"></span><span id="deprecated-features-3-1"></span><h2>在 3.1 中被废弃的功能<a class="headerlink" href="#features-deprecated-in-3-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-postgresql-jsonfield">
<span id="s-deprecated-jsonfield"></span><span id="postgresql-jsonfield"></span><span id="deprecated-jsonfield"></span><h3>PostgreSQL 的 <code class="docutils literal notranslate"><span class="pre">JSONField</span></code><a class="headerlink" href="#postgresql-jsonfield" title="永久链接至标题">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.field.JSONField</span></code> 和 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.JSONField</span></code> 被废弃，改用 <a class="reference internal" href="../ref/models/fields.html#django.db.models.JSONField" title="django.db.models.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">models.JSONField</span></code></a> 和 <a class="reference internal" href="../ref/forms/fields.html#django.forms.JSONField" title="django.forms.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">forms.JSONField</span></code></a>。</p>
<p>未记录的 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.jsonb.KeyTransform</span></code> 和 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.jsonb.KeyTextTransform</span></code> 也被弃用，改用 <code class="docutils literal notranslate"><span class="pre">django.db.models.fields.json</span></code> 中的变换。</p>
<p>新的 <code class="docutils literal notranslate"><span class="pre">JSONField</span></code>、<code class="docutils literal notranslate"><span class="pre">KeyTransform</span></code> 和 <code class="docutils literal notranslate"><span class="pre">KeyTextTransform</span></code> 可用于所有支持的数据库后端。</p>
</div>
<div class="section" id="s-id2">
<span id="id2"></span><h3>杂项<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h3>
<ul>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT_DAYS</span></code> 配置已被取消，改为 <a class="reference internal" href="../ref/settings.html#std:setting-PASSWORD_RESET_TIMEOUT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PASSWORD_RESET_TIMEOUT</span></code></a>。</p>
</li>
<li><p class="first">未记录的 <a class="reference internal" href="../ref/models/querysets.html#std:fieldlookup-isnull"><code class="xref std std-lookup docutils literal notranslate"><span class="pre">isnull</span></code></a> 查找使用非布尔值作为右侧的用法已被废弃，请使用 <code class="docutils literal notranslate"><span class="pre">True</span></code> 或 <code class="docutils literal notranslate"><span class="pre">False</span></code> 代替。</p>
</li>
<li><p class="first">勉强记录的 <code class="docutils literal notranslate"><span class="pre">django.db.models.query_utils.InvalidQuery</span></code> 异常类被废弃，取而代之的是 <a class="reference internal" href="../ref/exceptions.html#django.core.exceptions.FieldDoesNotExist" title="django.core.exceptions.FieldDoesNotExist"><code class="xref py py-class docutils literal notranslate"><span class="pre">FieldDoesNotExist</span></code></a> 和 <a class="reference internal" href="../ref/exceptions.html#django.core.exceptions.FieldError" title="django.core.exceptions.FieldError"><code class="xref py py-class docutils literal notranslate"><span class="pre">FieldError</span></code></a>。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">django-admin.py</span></code> 的入口点已被废弃，改为 <code class="docutils literal notranslate"><span class="pre">django-admin</span></code>。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">HttpRequest.is_ajax()</span></code> 方法已被废弃，因为它依赖于 jQuery 特定的方式来表示 AJAX 调用，而当前的用法倾向于使用 JavaScript <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API</a> 。根据你的用例，你可以写你自己的 AJAX 检测方法，或者使用新的 <a class="reference internal" href="../ref/request-response.html#django.http.HttpRequest.accepts" title="django.http.HttpRequest.accepts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpRequest.accepts()</span></code></a> 方法，如果你的代码依赖于客户端 <code class="docutils literal notranslate"><span class="pre">Accept</span></code> HTTP 头。</p>
<p>如果你正在编写自己的 AJAX 检测方法，<code class="docutils literal notranslate"><span class="pre">request.is_ajax()</span></code> 可以完全复制为 <code class="docutils literal notranslate"><span class="pre">request.headers.get('x-requested-with')</span> <span class="pre">==</span> <span class="pre">'XMLHttpRequest'</span></code>。</p>
</li>
<li><p class="first">传递 <code class="docutils literal notranslate"><span class="pre">None</span></code> 作为 <code class="docutils literal notranslate"><span class="pre">django.utils.deprecation.MiddlewareMixin.__init__()</span></code> 的第一个参数是过时的。</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/contrib/messages.html#django.contrib.messages.storage.cookie.CookieStorage" title="django.contrib.messages.storage.cookie.CookieStorage"><code class="xref py py-class docutils literal notranslate"><span class="pre">CookieStorage</span></code></a> 使用的 cookie 值的编码格式与旧版本 Django 生成的格式不同。在 Django 4.0 之前，仍然支持旧的格式。</p>
</li>
<li><p class="first">会话的编码格式与旧版 Django 生成的格式不同。在 Django 4.0 之前，仍然支持旧的格式。</p>
</li>
<li><p class="first"><a class="reference internal" href="../topics/signals.html#django.dispatch.Signal" title="django.dispatch.Signal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signal</span></code></a> 的纯文档化 <code class="docutils literal notranslate"><span class="pre">providing_args</span></code> 参数已被废弃。如果你依赖这个参数作为文档，你可以将文本移到代码注释或 docstring 中。</p>
</li>
<li><p class="first">没有 <code class="docutils literal notranslate"><span class="pre">length</span></code> 参数的情况下调用 <code class="docutils literal notranslate"><span class="pre">django.utils.crypto.get_random_string()</span></code> 已被废弃。</p>
</li>
<li><p class="first"><a class="reference internal" href="../ref/forms/fields.html#django.forms.ModelMultipleChoiceField" title="django.forms.ModelMultipleChoiceField"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModelMultipleChoiceField</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">list</span></code> 信息已被弃用，改为 <code class="docutils literal notranslate"><span class="pre">invalid_list</span></code>。</p>
</li>
<li><p class="first">向 <a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.order_by" title="django.db.models.query.QuerySet.order_by"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.order_by()</span></code></a> 传递原始列别名已经被废弃。通过事先在 <a class="reference internal" href="../ref/models/expressions.html#django.db.models.expressions.RawSQL" title="django.db.models.expressions.RawSQL"><code class="xref py py-class docutils literal notranslate"><span class="pre">RawSQL</span></code></a> 中传递别名，可以达到同样的效果。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">NullBooleanField</span></code> 模型字段被废弃，改为 <code class="docutils literal notranslate"><span class="pre">BooleanField(null=True)</span></code>。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">django.conf.urls.url()</span></code> 的 <a class="reference internal" href="../ref/urls.html#django.urls.re_path" title="django.urls.re_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.urls.re_path()</span></code></a> 别名已被废弃。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">ifequal</span> <span class="pre">%}</span></code> 和 <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">ifnotequal</span> <span class="pre">%}</span></code> 模板标签已被废弃，改为 <a class="reference internal" href="../ref/templates/builtins.html#std:templatetag-if"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></code></a>。<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></code> 涵盖了所有的用例，但如果你需要继续使用这些标签，可以将它们从 Django 中提取到一个模块中，并作为一个内置标签包含在 <a class="reference internal" href="../topics/templates.html#django.template.backends.django.DjangoTemplates" title="django.template.backends.django.DjangoTemplates"><code class="xref py py-class docutils literal notranslate"><span class="pre">'buildins'</span></code></a> 选项中的 <a class="reference internal" href="../ref/settings.html#std:setting-TEMPLATES-OPTIONS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">OPTIONS</span></code></a> 中。</p>
</li>
<li><p class="first"><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code> 过渡性配置已废弃。</p>
</li>
</ul>
</div>
</div>
<div class="section" id="s-features-removed-in-3-1">
<span id="s-removed-features-3-1"></span><span id="features-removed-in-3-1"></span><span id="removed-features-3-1"></span><h2>3.1 中删除的功能<a class="headerlink" href="#features-removed-in-3-1" title="永久链接至标题">¶</a></h2>
<p>这些功能已经到了废弃周期，在 Django 3.1 中被删除。</p>
<p>参见 <a class="reference internal" href="2.2.html#deprecated-features-2-2"><span class="std std-ref">在 2.2 中被废弃的功能</span></a>，了解这些变化的细节，包括如何删除这些功能的使用。</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">django.utils.timezone.FixedOffset</span></code> 被删除。</li>
<li><code class="docutils literal notranslate"><span class="pre">django.core.paginator.QuerySetPaginator</span></code> 被删除。</li>
<li>一个模型的 <code class="docutils literal notranslate"><span class="pre">Meta.ordering</span></code> 不影响 <code class="docutils literal notranslate"><span class="pre">GROUP</span> <span class="pre">BY</span></code> 的查询。</li>
<li><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.fields.FloatRangeField</span></code> 和 <code class="docutils literal notranslate"><span class="pre">django.contrib.postgres.forms.FloatRangeField</span></code> 被删除。</li>
<li><code class="docutils literal notranslate"><span class="pre">FILE_CHARSET</span></code> 配置被删除。</li>
<li><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.storage.CachedStaticFilesStorage</span></code> 被删除。</li>
<li><code class="docutils literal notranslate"><span class="pre">RemoteUserBackend.configure_user()</span></code> 方法需要 <code class="docutils literal notranslate"><span class="pre">request</span></code> 作为第一个位置参数。</li>
<li>取消对 <code class="docutils literal notranslate"><span class="pre">SimpleTestCase.allow_database_queries</span></code> 和 <code class="docutils literal notranslate"><span class="pre">TransactionTestCase.multi_db</span></code> 的支持。</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Django 3.1 版本发行说明</a><ul>
<li><a class="reference internal" href="#python-compatibility">Python 兼容性</a></li>
<li><a class="reference internal" href="#what-s-new-in-django-3-1">Django 3.1 新特性</a><ul>
<li><a class="reference internal" href="#asynchronous-views-and-middleware-support">异步视图和中间件支持</a></li>
<li><a class="reference internal" href="#jsonfield-for-all-supported-database-backends">JSONField 适用于所有支持的数据库后端。</a></li>
<li><a class="reference internal" href="#default-hashing-algorithm-settings"><code class="docutils literal notranslate"><span class="pre">DEFAULT_HASHING_ALGORITHM</span></code> 配置</a></li>
<li><a class="reference internal" href="#minor-features">次要特性</a><ul>
<li><a class="reference internal" href="#django-contrib-admin"><code class="docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-auth"><code class="docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-contenttypes"><code class="docutils literal notranslate"><span class="pre">django.contrib.contenttypes</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-gis"><code class="docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-humanize"><code class="docutils literal notranslate"><span class="pre">django.contrib.humanize</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-postgres"><code class="docutils literal notranslate"><span class="pre">django.contrib.postgres</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-sessions"><code class="docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-staticfiles"><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles</span></code></a></li>
<li><a class="reference internal" href="#cache">缓存</a></li>
<li><a class="reference internal" href="#csrf">CSRF</a></li>
<li><a class="reference internal" href="#email">电子邮件</a></li>
<li><a class="reference internal" href="#error-reporting">错误报告</a></li>
<li><a class="reference internal" href="#file-storage">文件存储</a></li>
<li><a class="reference internal" href="#forms">表单</a></li>
<li><a class="reference internal" href="#internationalization">国际化</a></li>
<li><a class="reference internal" href="#management-commands">管理命令</a></li>
<li><a class="reference internal" href="#models">模型</a></li>
<li><a class="reference internal" href="#pagination">分页</a></li>
<li><a class="reference internal" href="#requests-and-responses">请求和响应</a></li>
<li><a class="reference internal" href="#security">安全</a></li>
<li><a class="reference internal" href="#templates">模板</a></li>
<li><a class="reference internal" href="#tests">测试</a></li>
<li><a class="reference internal" href="#urls">URLs</a></li>
<li><a class="reference internal" href="#utilities">实用程序</a></li>
<li><a class="reference internal" href="#miscellaneous">杂项</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#backwards-incompatible-changes-in-3-1">3.1 中的不向后兼容的变更</a><ul>
<li><a class="reference internal" href="#database-backend-api">数据库后端 API</a></li>
<li><a class="reference internal" href="#dropped-support-for-mariadb-10-1">丢弃了对 MariaDB 10.1 的支持</a></li>
<li><a class="reference internal" href="#contrib-admin-browser-support"><code class="docutils literal notranslate"><span class="pre">contrib.admin</span></code> 浏览器支持</a></li>
<li><a class="reference internal" href="#abstractuser-first-name-max-length-increased-to-150"><code class="docutils literal notranslate"><span class="pre">AbstractUser.first_name</span></code> 的 <code class="docutils literal notranslate"><span class="pre">max_length</span></code> 增加到 150</a></li>
<li><a class="reference internal" href="#id1">杂项</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-deprecated-in-3-1">在 3.1 中被废弃的功能</a><ul>
<li><a class="reference internal" href="#postgresql-jsonfield">PostgreSQL 的 <code class="docutils literal notranslate"><span class="pre">JSONField</span></code></a></li>
<li><a class="reference internal" href="#id2">杂项</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-removed-in-3-1">3.1 中删除的功能</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="3.1.1.html"
                        title="上一章">Django 3.1.1 版本发行说明</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="3.0.14.html"
                        title="下一章">Django 3.0.14 版本发行说明</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/releases/3.1.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="3.1.1.html" title="Django 3.1.1 版本发行说明">previous</a>
     |
    <a href="index.html" title="发行说明" accesskey="U">up</a>
   |
    <a href="3.0.14.html" title="Django 3.0.14 版本发行说明">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>